{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "from common import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "RESULT_JSON = \"/Users/law/repos/viper/results/update/update_bm_revision.json\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from collections import defaultdict\n",
    "runs = defaultdict(list)\n",
    "\n",
    "BMS = get_all_runs(RESULT_JSON)\n",
    "IN_PLACE = 'in_place'\n",
    "COPY_WRITE = 'get_update'\n",
    "\n",
    "for bm in BMS:\n",
    "    if IN_PLACE in bm['name']:\n",
    "        runs[IN_PLACE].append(bm)\n",
    "    elif COPY_WRITE in bm['name']:\n",
    "        runs[COPY_WRITE].append(bm)\n",
    "    else:\n",
    "        raise RuntimeError(f\"Unknown benchmark type {bm['name']}\")\n",
    "\n",
    "runs[IN_PLACE].sort(key=lambda x: x['threads'])\n",
    "runs[COPY_WRITE].sort(key=lambda x: x['threads'])\n",
    "\n",
    "# pprint(runs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "in_place_w_threads = [(run['threads'], run['items_per_second'] / MILLION) for run in runs[IN_PLACE]]\n",
    "copy_write = [run['items_per_second'] / MILLION for run in runs[COPY_WRITE]]\n",
    "\n",
    "threads, in_place = zip(*in_place_w_threads)\n",
    "\n",
    "fig, ax = plt.subplots(1, 1, figsize=(4, 3))\n",
    "\n",
    "ax.plot(threads, in_place, label=\"In-Place\", ls='-', color=PMEM_COLOR, lw=3)\n",
    "ax.plot(threads, copy_write, label=\"CoW\", ls='--', color=DRAM_COLOR, lw=3)\n",
    "ax.set_yticks(range(0, 16, 5))\n",
    "\n",
    "ax.set_ylabel(\"Throughput\\n(Mops/s)\", fontsize=18)\n",
    "ax.set_xlabel(\"# Threads\", fontsize=18)\n",
    "ax.legend(frameon=False, loc='upper left', fontsize=18,\n",
    "          columnspacing=1.3, handletextpad=0.3, labelspacing=0.1,\n",
    "         bbox_to_anchor=(-0.05, 1.25))\n",
    "\n",
    "for tick in ax.xaxis.get_major_ticks():\n",
    "    tick.label.set_fontsize(18)\n",
    "for tick in ax.yaxis.get_major_ticks():\n",
    "    tick.label.set_fontsize(18)\n",
    "\n",
    "# ax.yaxis.set_label_coords(-0.12, 0.45)\n",
    "\n",
    "ax.set_axisbelow(True)\n",
    "ax.grid(axis='y', which='major')\n",
    "hide_border(ax)\n",
    "plt.tight_layout()\n",
    "fig.savefig('charts/update.pdf', bbox_inches='tight')\n",
    "fig.savefig('charts/update.svg', bbox_inches='tight')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
